<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>修改会员信息</title>
<meta name="renderer" content="webkit">	
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">	
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">	
<meta name="apple-mobile-web-app-status-bar-style" content="black">	
<meta name="apple-mobile-web-app-capable" content="yes">	
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/index.css">
<link rel="stylesheet" href="css/table.css">
</head>
<body>
	<div class="content-head">悦宝园会员管理系统</div>
	<div class="content-main">
		<div class="side-nav" ms-controller="navBar">
			<ul class="nav-item">
				<li><a href="main.html" class="nav-item-front nav-item-add">首页</a></li>
				<li ms-for="el in @navTitleArr">
					<a href="javascript:;" class="nav-item-front">{{el.par}}</a>
					<dl class="nav-item-child">
						<dd ms-for="($index, ex) in el.child"><a ms-attr='{href: el.href[$index]}'>{{ex}}</a></dd>
					</dl>
				</li>
			</ul>
		</div>
		<div class="content bg-gray"  ms-controller="main">
			<div class="tab-content">
				<div class="tab-item">
					<div class="sub-main">
						<p class="sub-title"><i>修改会员信息</i></p>
						<div class="import-area">
							<div class="import-block">
								<span class="import-name">宝宝姓名：</span>
								<div class="import-input">
									<input type="text" maxlength="20" ms-duplex="@name" id="name">
									<span class="connectOtherName" ms-html="@iconnect()"></span>
									<a href="javascript:;" class="connectOther" id="connectOther">关联会员</a>
								</div>
							</div>
							<div class="import-block">
								<span class="import-name">宝宝小名：</span>
								<div class="import-input"><input type="text" maxlength="20" ms-duplex="@nickName" id="nickName"></div>
							</div>
							<div class="import-block">
								<span class="import-name">出生日期：</span>
								<div class="import-input"><input type="date" maxlength="20" ms-duplex="@birthday" id="birthday"></div>
							</div>
							<div class="import-block">
								<span class="import-name">家长姓名：</span>
								<div class="import-input"><input type="text" maxlength="20" ms-duplex="@paName" id="paName"></div>
							</div>
							<div class="import-block">
								<span class="import-name">电话：</span>
								<div class="import-input"><input type="tel" maxlength="11" ms-duplex="@tel" id="tel"></div>
							</div>
							<div class="import-block">
								<span class="import-name">剩余课时：</span>
								<div class="import-input"><input type="text" maxlength="3" style="width:50px;" ms-duplex-number="@classNum" id="classNum" disabled="disabled">课时<a href="javascript:;" class="connectOther" id="addClass">续课</a></div>
							</div>
							<div class="import-block">
								<span class="import-name">所属顾问：</span>
								<div class="import-input">
									<select ms-duplex="@cc">
										<option value="Maggie">Maggie</option>
										<option value="Anna">Anna</option>
										<option value="Lisa">Lisa</option>
										<option value="Mia">Mia</option>
										<option value="Katie">Katie</option>
										<option value="Ivy">Ivy</option>
										<option value="Lucas">Lucas</option>
										<option value="Amy">Amy</option>
									</select>
								</div>
							</div>
							<div class="import-block">
								<span class="import-name">会员来源：</span>
								<div class="import-input">
									<select ms-duplex="@source">
										<option value="1" selected="selected">毛单</option>
										<option value="2">采单</option>
										<option value="3">异业推荐</option>
										<option value="4">地推活动</option>
										<option value="5">转介绍</option>
										<option value="6">walk in</option>
										<option value="7">call in</option>
										<option value="8">web in</option>
									</select>
								</div>
							</div>
							<div class="import-block">
								<span class="import-name"></span>
								<a href="javascript:;" class="import-btn" ms-on-click="@subForm">修改</a></div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
<script src="js/jq.js"></script>
<script src="js/avalon.js"></script>
<script src="js/main.js"></script>
<script>
(function() {
	var parName = baseFunc.getSessionData("jumppage");
	var dataObj = baseFunc.getStorageData("member", {flag: parName})[0];
	var obj = {};
	var copyObj = jQuery.extend(true, {}, dataObj);

	$("#connectOther").click(function() {
		baseFunc.locationSkip("connectAllMember.html");
	});

	$("#addClass").click(function() {
		baseFunc.locationSkip("addAddClass.html");
	});

	var freeClass = (function() {
		var freeObj = dataObj.freeClass,
			ids = 0;
		if(freeObj) {
			for (var i = 0; i < freeObj.length; i++) {
				ids += parseInt(freeObj[i].num);
			};
			return ids;
		}
		return ids;
	})()
	
	var vm = avalon.define({
	    $id: "main",
	    name: dataObj.name,
	    nickName: dataObj.nickName || "",
	    birthday: dataObj.birthday || "",
	    paName: dataObj.paName || "",
	    tel: dataObj.tel || "",
	    classNum: dataObj.classNum.formal || "",
	    price: dataObj.price || "",
	    period: dataObj.period || "",
	    cc: dataObj.cc || "",
	    source: dataObj.source || "",
	    buyDay: dataObj.buyDay || "",
	    iconnect: function() {
	    	if (dataObj.connect) {
	    		return "已关联" + dataObj.connect.flag.replace(/[0-9]/ig,"");
	    	};
	    	return "";
	    },
	    subForm: function() {
	    	obj.name = $.trim(this.name) || "";
	    	obj.nickName = $.trim(this.nickName) || "";
	    	obj.birthday = $.trim(this.birthday) || "";
	    	obj.paName = $.trim(this.faName) || "";
	    	obj.price = $.trim(this.price) || "";
	    	obj.period = $.trim(this.period) || "";
	    	obj.tel = $.trim(this.tel) || "";
	    	obj.classNum = {formal: parseInt($.trim(this.classNum)), free: freeClass} || "";
	    	obj.cc = $.trim(this.cc) || "";
	    	obj.source = $.trim(this.source) || "";
	    	obj.buyDay = $.trim(this.buyDay) || "";
	    	obj.upClassInfo = {}; //{ name: [观察期提醒，升班提醒] }
	    	obj.buyInfo = [];

	    	var resObj = baseFunc.valide(obj),
	    		status = true;

	    	var diffDate = function(newDate, oldDate) { //{[], []}
	    		var year = newDate[0]; //表示需要查找的年份
				var month = newDate[1];//表示需要查找的月份
				var curMonthDays = new Date(year,month,0).getDate(); //0表示3月的第0天，上月的最后一天,月份从0开始记数
				if(oldDate[2] > curMonthDays) {
					newDate[2] = curMonthDays;
				}

	    		return newDate[0] + "-" + newDate[1] + "-" + newDate[2];
	    	};

	    	var calcDate = function(arr, calcNum) {
	    		var oldY = parseInt(arr[0]),
	    			oldM = parseInt(arr[1]),
	    			oldD = parseInt(arr[2]),
	    			y = oldY,
	    			m = oldM,
	    			d = oldD,
	    			calcNum = parseInt(calcNum);

	    		if(calcNum == 12) {
	    			y += 1;
	    			return diffDate([y, m, d], [oldY, oldM, oldD]);
	    		}

	    		if(calcNum == 24) {
	    			y += 2;
	    			return diffDate([y, m, d], [oldY, oldM, oldD]);
	    		}

	    		if(calcNum < 12) {
	    			m = m + calcNum;
	    			if(m > 12) {
	    				y += 1;
	    				m -= 12;
	    			}
	    			return diffDate([y, m, d], [oldY, oldM, oldD]);
	    		}

	    		if(calcNum > 12) {
	    			y += 1;
	    			calcNum -= 12;
	    			m += calcNum;
	    			if(m > 12) {
	    				y += 1;
	    				m -= 12;
	    			}
	    			return diffDate([y, m, d], [oldY, oldM, oldD]);
	    		}
	    	};

	    	var inWhichTime = function(tipsDate, confirmDate) {
	    		//情况一刚好处于提醒日
	    		var day2 = new Date();
	    		day2.setTime(day2.getTime());
	    		var nowDate = day2.getFullYear() + "-" + (day2.getMonth()+1) + "-" + day2.getDate();
	    		var effDiff = baseFunc.dateDiff(tipsDate, confirmDate);
	    		var tipsDiff = baseFunc.dateDiff(tipsDate, nowDate);
	    		var confirmSplit = confirmDate.split("-");

		    	if(tipsDiff >= 0 && tipsDiff < effDiff) {
		    		return "inTips";
		    	}

	    		if(day2.getFullYear() == confirmSplit[0] && (day2.getMonth()+1) == confirmSplit[1] && day2.getDate() == confirmSplit[2]) {
	    			return "inConfirm";
	    		}
	    		return "free";
	    	};

	    	$(".valide").remove();

	    	for(var k in resObj) {
	    		if(resObj[k] === false) {
	    			$("#" + k).parent().append("<span class='valide' style='color:#e74c3c; padding:0 15px;'>输入不正确<span>");
	    			status = false;
	    		}
	    	}

	    	if(status) {
		    	//预存升班信息
		    	//观察期提醒，  升班提醒推后一个月
				//bb：  5个月， 6个月
				//tod:  9个月， 10个月
				//run： 15个月，16个月
				//tows：23个月，24个月			
				//m1：  9个月， 10个月
				//m2：  15个月，16个月
				//m3：  23个月，24个月
				//ae1： 15个月，16个月
				//ae2： 23个月，24个月

	    		var birthday = obj.birthday.split("-");
				obj.upClassInfo = {
					"bb": [calcDate(birthday, 5), calcDate(birthday, 6), inWhichTime(calcDate(birthday, 5), calcDate(birthday, 6))],
					"tod": [calcDate(birthday, 9), calcDate(birthday, 10), inWhichTime(calcDate(birthday, 9), calcDate(birthday, 10))],
					"run": [calcDate(birthday, 15), calcDate(birthday, 16), inWhichTime(calcDate(birthday, 15), calcDate(birthday, 16))],
					"twos": [calcDate(birthday, 23), calcDate(birthday, 24), inWhichTime(calcDate(birthday, 23), calcDate(birthday, 24))],
					"m1": [calcDate(birthday, 9), calcDate(birthday, 10), inWhichTime(calcDate(birthday, 9), calcDate(birthday, 10))],
					"m2": [calcDate(birthday, 15), calcDate(birthday, 16), inWhichTime(calcDate(birthday, 15), calcDate(birthday, 16))],
					"m3": [calcDate(birthday, 23), calcDate(birthday, 24), inWhichTime(calcDate(birthday, 23), calcDate(birthday, 24))],
					"ae1": [calcDate(birthday, 15), calcDate(birthday, 16), inWhichTime(calcDate(birthday, 15), calcDate(birthday, 16))],
					"ae2": [calcDate(birthday, 23), calcDate(birthday, 24), inWhichTime(calcDate(birthday, 23), calcDate(birthday, 24))]
				};

				obj.buyInfo.push({date: obj.buyDay, num: obj.classNum.formal, price: obj.price});
				if(dataObj.connect) {
					var pMember = baseFunc.getStorageData("member", {flag: dataObj.connect.flag})[0]; //关联账户同时改变	
					pMember.classNum.formal = obj.classNum.formal;
					baseFunc.editStorageData("member", pMember);
				}

				obj = avalon.mix(dataObj, obj);
	    		baseFunc.editStorageData("member", obj);
	    		baseFunc.locationSkip("allMember.html");
	    	}
	    }
	})
})();
</script>
</body>
</html>